<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('岗位列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="post-form">
					<div class="select-list">
						<ul>
							<li>
								岗位名称：<input type="text" name="positionName"/>
							</li>
							<li>
								公司名称：<input type="text" name="companyFullName"/>
							</li>
							<li>
								城市：<input type="text" name="city"/>
							</li>
							<li>
								薪资：<input type="text" name="salary"/>
							</li>
							<li>
								岗位状态：<select name="status">
								<option value="">所有</option>
								<option value="0">正常</option>
								<option value="1">关闭</option>
							</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()">
	                <i class="fa fa-plus"></i> 新增
	            </a>
				<a class="btn btn-primary single disabled" onclick="$.operate.edit()">
		            <i class="fa fa-edit"></i> 修改
		        </a>
				<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
		            <i class="fa fa-remove"></i> 删除
		        </a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()">
		            <i class="fa fa-download"></i> 导出
		        </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var prefix = ctx + "system/post";

		$(function() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        sortName: "postId",
		        modalName: "岗位",
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'postId',
		            title: '岗位编号',
					sortable: true
		        },
		        {
		            field: 'positionName',
		            title: '岗位名称',
					sortName: 'positionName',
					sortable: true
		        },
				{
					field: 'salary',
					title: '薪资',
					sortable: true
				},
		        {
		            field: 'companyFullName',
		            title: '公司名称',
		            sortable: true
		        },
		        {
		            field: 'companySize',
		            title: '公司规模',
		            sortable: true
		        },
				{
					field: 'financeStage',
					title: '融资阶段'
				},
				{
					field: 'workYear',
					title: '工作经验',
					sortable: true
				},
				{
					field: 'education',
					title: '学历要求',
					sortable: true
				},
				{
					field: 'positionAdvantage',
					title: '岗位福利',
					sortable: true
				},
				{
					field: 'city',
					title: '城市',
					sortable: true
				},
				{
					field: 'district',
					title: '区域',
					sortable: true
				},
		        {
		            field: 'status',
		            title: '状态',
		            align: 'center',
					formatter: function (value, row, index) {
						return statusTools(row);
					}
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
		                actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.postId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		                actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});

		/* 岗位状态显示 */
		function statusTools(row) {
			if (row.status === "1") {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.postId + '\')"></i> ';
			} else {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.postId + '\')"></i> ';
			}
		}

		/* 岗位管理-停用 */
		function disable(postId) {
			$.modal.confirm("确认要关闭岗位吗？", function () {
				$.operate.post(prefix + "/changeStatus", {"postId": postId, "status": 1});
			})
		}

		/* 岗位管理启用 */
		function enable(postId) {
			$.modal.confirm("确认要启用岗位吗？", function () {
				$.operate.post(prefix + "/changeStatus", {"postId": postId, "status": 0});
			})
		}
	</script>
</body>
</html>